﻿using System.ComponentModel;

namespace EzDeploy.Core
{
    internal class AssemblyInfoFlat
    {
        string _name;
        string _fullName;
        string _fullyQualifiedPath;
        string _version;
        VersionStatus _versionStatus;
        string _runtime;
        string _companyName;

        public AssemblyInfoFlat(DeployGridItem item)
        {
            _versionStatus = item.ItemStatus;
            _version = item.ItemVersion;
            
            if (item.ItemStatus != Core.VersionStatus.Unknown)
                this.SetValueForNonMissingAssembly(item);
            else
                this.SetValueForMissingAssembly(item);
        }

        private void SetValueForNonMissingAssembly(DeployGridItem item)
        {
            _name = item.AssemblyName.Name;
            _fullName = item.AssemblyName.FullName;
            _fullyQualifiedPath = item.AssemblyName.FullyQualifiedPath;
            _runtime = CecilUtility.ToFriendlyName(item.AssemblyName.Runtime);

            _companyName = item.AssemblyName.Attributes["AssemblyCompany"];
        }

        private void SetValueForMissingAssembly(DeployGridItem item)
        {
            _name = item.AssemblyName.Name;
            _fullName = item.AssemblyName.FullName;
            _fullyQualifiedPath = item.AssemblyName.FullyQualifiedPath;

            _runtime = "Unknown";
        }

        [Category("Assembly")]
        [DisplayName("1. Name")]
        public string Name
        {
            get
            {
                return _name;
            }
        }
        [Category("Assembly")]
        [DisplayName("2. FullName")]
        public string FullName
        {
            get
            {
                return _fullName;
            }
        }
        [Category("Assembly")]
        [DisplayName("5. Path")]
        public string FullyQualifiedPath
        {
            get
            {
                return _fullyQualifiedPath;
            }
        }

        [DisplayName("Status")]
        public VersionStatus VersionStatus
        {
            get
            {
                return _versionStatus;
            }
        }

        [DisplayName("4. Runtime")]
        [Category("Assembly")]
        public string Runtime
        {
            get
            {
                return _runtime;
            }
        }
        [DisplayName("3. Version")]
        [Category("Assembly")]
        public string Version
        {
            get
            {
                return _version;
            }
        }

        [DisplayName("Company Name")]
        public string CompanyName
        {
            get
            {
                return _companyName;
            }
        }
    }
}
